package com.cw.aop;

import com.cw.mapper.OperateLogMapper;
import com.cw.pojo.OperateLog;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class LogAspect {
    @Autowired //注入接口
    private OperateLogMapper operateLogMapper;
    @Around("@annotation(com.cw.anno.Log)") // 环绕通知
    public Object recordLog(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        //操作人ID - 当前登录员工ID

        //调用原始目标方法运行
        Object result = proceedingJoinPoint.proceed();

        OperateLog operateLog = new OperateLog();
        operateLogMapper.insert(operateLog);
        return result;
    }
}
